MkList
Node for showing a formatted list.¶
Bases: MkContainer
__init__
¶
__init__(
items: Sequence[str | MkNode] | None = None,
*,
ordered: bool = False,
shorten_after: int | None = None,
as_links: bool = False,
**kwargs: Any
)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items
|
Sequence[str | MkNode] | None
|
Items to show as a list |
None
|
ordered
|
bool
|
whether the list should be numbered |
False
|
shorten_after
|
int | None
|
will clip the list after n items and append a "..." |
None
|
as_links
|
bool
|
will convert the label to links which will get replaced by plugin |
False
|
kwargs
|
Any
|
Keyword arguments passed to parent |
{}
|
Name | Children | Inherits |
---|---|---|
MkContainer mknodes.basenodes.mkcontainer A node containing other MkNodes. |
graph TD
94721311728912["mklist.MkList"]
94721311697232["mkcontainer.MkContainer"]
94721308848336["mknode.MkNode"]
94721311766592["node.Node"]
140564252373184["builtins.object"]
94721311697232 --> 94721311728912
94721308848336 --> 94721311697232
94721311766592 --> 94721308848336
140564252373184 --> 94721311766592
/home/runner/work/mknodes/mknodes/mknodes/basenodes/mklist/metadata.toml
[metadata]
name = "MkList"
group = "container"
icon = "octicon:list-unordered-24"
[requirements.extension.def_list]
[examples.regular]
title = "Regular"
jinja = """
{{ ["Item 1", "Item 2", "Item 3"] | MkList }}
"""
[examples.shorten]
title = "Shorten"
jinja = """
{{ ["Item 1", "Item 2", "Item 3"] | MkList(shorten_after=2) }}
"""
[examples.ordered]
title = "Ordered"
jinja = """
{{ ["Item 1", "Item 2", "Item 3"] | MkList(ordered=True) }}
"""
[examples.nested]
title = "Nested"
jinja = """
{{ [_mk.MkAdmonition("Nested!")] | MkList }}
"""
[output.markdown]
template = """
{% for item in node.items[: node.shorten_after] %}
{{ (loop.index ~ ".") if node.ordered else "*" }} {{ node._prep(item)}}
{% endfor %}
{% if node.shorten_after and node.items | length > node.shorten_after %}
{{ (node.shorten_after + 1 ~ ".") if node.ordered else "*" }} ...
{% endif %}
"""
[output.html]
template = """
<{{ "ol" if node.ordered else "ul" }}>{% for item in node.items[: node.shorten_after] %}<li>{{ node._prep(item)}}</li>{% endfor %}
{% if node.shorten_after and node.items | length > node.shorten_after %}
<li>...</li>{% endif %}
</{{ "ol" if node.ordered else "ul" }}>
"""